package cn.itcast.item.filter;

import cn.itcast.hmall.dto.common.ThreadLocalUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Component
public class HmallFilter implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String authorization = request.getHeader("authorization");
        if ("2".equals(authorization)) {
            ThreadLocalUtil.setUserId(Long.getLong(authorization));
        }
        return true;
    }
}
